package com.lagou.rpc.provider.rpc;

import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.CreateMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ServiceRegister {

    private static final String SERVICES_PATH = "/lg-rpc/services";

    @Autowired
    private CuratorFramework curatorFramework;

    public void registerService(String ip, int port) throws Exception {
        String serviceAddr = ip + ":" + port;
        curatorFramework.create()
                .creatingParentsIfNeeded()
                .withMode(CreateMode.EPHEMERAL)
                .forPath(SERVICES_PATH + "/" + serviceAddr);
    }

}
